    package com.yy.controller.mapper;

import com.github.pagehelper.Page;
import com.yy.dto.AdminUserLoginDTO;
import com.yy.dto.AdminUserPageQueryDTO;
import com.yy.entity.AdminUser;
import com.yy.vo.AdminUserVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;

@Mapper
public interface AdminUserMapper {
    /**
     * 根据账号名查询账号信息
     * @param adminUserLoginDTO
     * @return
     */
     @Select("select * from admin_user where username=#{username}")
     AdminUser getByUsername(AdminUserLoginDTO adminUserLoginDTO);

    /**
     * 分页条件查询账号列表
     * @param adminUserPageQueryDTO
     * @return
     */
     Page<AdminUserVO> getPageList(AdminUserPageQueryDTO adminUserPageQueryDTO);

    /**
     * 根据id查询账号信息
     * @param id
     * @return
     */
     @Select("select * from  admin_user where id=#{id}")
     AdminUser getById(@Param("id") Long id);

    /**
     *新增账号
     * @return
     */
   @Insert("insert into admin_user (name, username, password, status, permissions, " +
             "create_time, update_time, create_user, update_user) " +
             "values (#{name},#{username},#{password}," +
             "#{status},#{permissions},#{createTime},#{updateTime}," +
             "#{createUser},#{updateUser})")
    void insert(AdminUser adminUser);

    /**
     * 删除账号
     * @param id
     */
    @Delete("delete from admin_user where id=#{id} ")
    void delete(Long id);


    /**
     * 根据id修改账号状态
     * @param id
     * @param status
     * @param updateUser
     * @param updateTime
     */
    @Update("update  admin_user set status=#{status},update_user=#{updateUser}," +
            "update_time=#{updateTime} where id=#{id}")
    void editeStatus(Long id, Integer status, Long updateUser, LocalDateTime updateTime);

    /**
     * 根据id重置账号密码
     * @param id
     * @param password
     * @param updateUser
     * @param updateTime
     */
    @Update("update  admin_user set password=#{password},update_user=#{updateUser}" +
            ",update_time=#{updateTime}  where id=#{id}")
    void resetPwd(Long id, String password, Long updateUser, LocalDateTime updateTime);

    /**
     * 根据账号名修改密码
     * @param adminUser
     */
    @Update("update admin_user set password=#{password}" +
            ",update_user=#{updateUser},update_time=#{updateTime} where username=#{username}")
    void updatePassword(AdminUser adminUser);
}
